home *** CD-ROM | disk | FTP | other *** search
- /*
- * AppleEvent Builder test tool
- * by Jens Peter Alfke
- *
- * How it works: Each argument will be sent to AEBuild, then AEPrint, and the end
- * result printed. It reports syntax errors in a semi-human-readable fashion.
- * If there are no arguments it asks for a line of input from the user.
- *
- * NOTE: This code was written in MPW C.
- *
- * Copyright ©1991 Apple Computer, Inc. All rights reserved.
- *
- * APPLE CONFIDENTIAL
- */
-
- #include <stdio.h>
- #include <AppleEvents.h>
- #include "sneJ:Work:AEBuilder:AEBuild.h"
- #include "sneJ:Work:AEBuilder:AEBuildGlobals.h"
- #include "sneJ:Work:AEBuilder:AEPrint.h"
-
-
- char *AEBuild_ErrMsgs[] = {
- "[No Error!]",
- "Illegal character",
- "Unexpectedly fell off end of line",
- "Extra stuff past end of descriptor",
- "“-” not followed by a number",
- "Missing close “'”",
- "Illegal digit in hex string",
- "Hex string has an odd number of digits",
- "Missing “»”",
- "Hex string must be coerced to some data type",
- "Missing “””",
- "Illegal descriptor",
- "Illegal data value inside parentheses",
- "Expected “)” after data value",
- "Expected “]” or “,” after a list item",
- "Expected “}” or “,” after a record item",
- "Expected a record keyword",
- "Missing “:” after record keyword"
- };
-
-
- int main( int argc, char *argv[] );
-
-
- int
- main( int argc, char *argv[] )
- {
- int i;
- OSErr err;
- AEDesc desc;
- char *str, strbuf[1024];
-
- for( i=1; i<argc || i==1; i++ ) {
- if( i>1 )
- printf("#\n");
- else
- printf("### AEBuildDemo:\n");
-
- printf("# Input: ");
- if( i<argc )
- puts( str = argv[i] );
- else {
- puts("[Please enter a descriptor string and press Enter:]");
- gets(strbuf);
- str = strbuf;
- }
- err= AEBuild(&desc, str);
- if( err ) {
- long j;
-
- if( i<argc )
- printf("# ");
- for( j=1; j<AEBuild_ErrPos; j++ )
- putchar(' ');
- printf("^\n# ");
- if( err==aeBuild_SyntaxErr )
- printf("Syntax error: %s\n", AEBuild_ErrMsgs[AEBuild_ErrCode]);
- else
- printf("**Error %d in AEBuild**\n",err);
- } else {
- sprintf(strbuf, "Built '%.4s' desc at %p, %d bytes of data at %p",
- &desc.descriptorType, &desc,
- GetHandleSize(desc.dataHandle), &(**desc.dataHandle));
- debugstr(strbuf);
-
- printf("# Output: ");
- err= AEPrint(&desc, strbuf,sizeof(strbuf));
- if( err )
- printf("**Error %d in AEPrint**\n", err);
- else
- puts(strbuf);
- }
- }
- return 0;
- }
-